#!/usr/bin/perl

use lib::abs qw( .. ../../base_lib );
use JIP::ToolSet;
use English qw( -no_match_vars );
use Test::More qw( no_plan );

#-- testing classes ------------------------------------------------------------
package Net::FTP::Client::Test;

use parent qw( Net::FTP::Client );

sub _initConnection {
    my $self = shift;

    $self->{'_connection'} = 'Net::FTP';

    return $self;
}

sub _initListingDecorator {
    my $self = shift;

    return $self;
}

#-- testing --------------------------------------------------------------------
package main;

BEGIN { use_ok 'Net::FTP::Client'; }
require_ok 'Net::FTP::Client';

can_ok 'Net::FTP::Client', qw(
    new
    init
    dir
    _host
    _timeout
    _user
    _pass
    _connection
    _initConnection
    _listingDecorator
    _initListingDecorator
);

my $c = Net::FTP::Client::Test->new(
    host    => '127.0.0.1',
    timeout => 1,
    user    => 'anonymous',
    pass    => 'upyachka_fighter',
);

isa_ok $c, 'Net::FTP::Client::Test';
isa_ok $c, 'Net::FTP::Client';
isa_ok $c, 'Class::Base';
isa_ok $c, 'Class::Accessor::Fast';

is $c->_host,    '127.0.0.1',        '_host accessor';
is $c->_timeout, 1,                  '_timeout accessor';
is $c->_user,    'anonymous',        '_user accessor';
is $c->_pass,    'upyachka_fighter', '_pass accessor';

try {
    $c->_host('tratata');
}
catch {
    like(
        $ARG,
        qr/^'main'\scannot\salter\sthe\svalue\sof\s'_host'/xms,
        'r.o. access to _host'
    );
};

try {
    $c->_timeout('tratata');
}
catch {
    like(
        $ARG,
        qr/^'main'\scannot\salter\sthe\svalue\sof\s'_timeout'/xms,
        'r.o. access to _timeout'
    );
};

try {
    $c->_user('tratata');
}
catch {
    like(
        $ARG,
        qr/^'main'\scannot\salter\sthe\svalue\sof\s'_user'/xms,
        'r.o. access to _user'
    );
};

try {
    $c->_pass('tratata');
}
catch {
    like(
        $ARG,
        qr/^'main'\scannot\salter\sthe\svalue\sof\s'_pass'/xms,
        'r.o. access to _pass'
    );
};

try {
    $c->_connection('tratata');
}
catch {
    like(
        $ARG,
        qr/^'main'\scannot\salter\sthe\svalue\sof\s'_connection'/xms,
        'r.o. access to _connection'
    );
};

try {
    $c->_listingDecorator('tratata');
}
catch {
    like(
        $ARG,
        qr/^'main'\scannot\salter\sthe\svalue\sof\s'_listingDecorator'/xms,
        'r.o. access to _listingDecorator'
    );
};

try {
    Net::FTP::Client->new();
}
catch {
    like(
        $ARG,
        qr/^required\sparameter\s"host"\snot\sdefined/xms,
        'new() - required parameter "host"'
    );
};

try {
    Net::FTP::Client->new( host => '127.0.0.1' );
}
catch {
    like(
        $ARG,
        qr/^required\sparameter\s"timeout"\snot\sdefined/xms,
        'new() - required parameter "timeout"'
    );
};

try {
    Net::FTP::Client->new(
        host    => '127.0.0.1',
        timeout => 1,
    );
}
catch {
    like(
        $ARG,
        qr/^required\sparameter\s"user"\snot\sdefined/xms,
        'new() - required parameter "user"'
    );
};

try {
    Net::FTP::Client->new(
        host    => '127.0.0.1',
        timeout => 1,
        user    => 'anonymous',
    );
}
catch {
    like(
        $ARG,
        qr/^required\sparameter\s"pass"\snot\sdefined/xms,
        'new() - required parameter "pass"'
    );
};
